package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.GregorianCalendarAddDTO;
import org.jsola.hr.dto.GregorianCalendarUpdateDTO;
import org.jsola.hr.entity.GregorianCalendarDO;
import org.jsola.hr.query.GregorianCalendarQuery;
import org.jsola.hr.service.IGregorianCalendarService;
import org.jsola.hr.vo.GregorianCalendarVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class GregorianCalendarTestHelper extends BaseTestHelper {
    
    @Autowired
    private IGregorianCalendarService gregorianCalendarService;

    /**
     * 生成add测试数据
     * @return GregorianCalendarAddDTO
     */
    public GregorianCalendarAddDTO getGregorianCalendarAddDTO(){
        GregorianCalendarAddDTO gregorianCalendarAddDTO = new GregorianCalendarAddDTO();
        gregorianCalendarAddDTO.setYearly(getRandomValue("varchar",10));
        gregorianCalendarAddDTO.setMonthly(getRandomValue("varchar",10));
        gregorianCalendarAddDTO.setDaily(getRandomValue("varchar",10));
        gregorianCalendarAddDTO.setDateStr(getRandomValue("varchar",20));
        gregorianCalendarAddDTO.setDateType(SafeKit.getInteger(getRandomValue("int",0)));
        gregorianCalendarAddDTO.setCompanyId(getRandomValue("varchar",32));
        return gregorianCalendarAddDTO;
    }


    /**
     * 生成update测试数据
     * @return GregorianCalendarUpdateDTO
     */
    public GregorianCalendarUpdateDTO getGregorianCalendarUpdateDTO(GregorianCalendarVO gregorianCalendarVO){
        return gregorianCalendarService.selectDOById(gregorianCalendarVO.getId(), SITE_ID).to(GregorianCalendarUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return GregorianCalendarQuery
     */
    public GregorianCalendarQuery getGregorianCalendarQuery() {
        GregorianCalendarQuery gregorianCalendarQuery = new GregorianCalendarQuery();
        List<GregorianCalendarDO> gregorianCalendarDOList = gregorianCalendarService.list(new GregorianCalendarDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(gregorianCalendarDOList)) {
            GregorianCalendarDO gregorianCalendarDO = gregorianCalendarDOList.get(0);
            gregorianCalendarQuery = gregorianCalendarDO.to(GregorianCalendarQuery.class);
            if (gregorianCalendarDO.getGmtCreate() != null) {
                gregorianCalendarQuery.setGmtCreateStart(DateKit.getBeforeDay(gregorianCalendarDO.getGmtCreate(),-1));
                gregorianCalendarQuery.setGmtCreateEnd(DateKit.getBeforeDay(gregorianCalendarDO.getGmtCreate(),1));
            }
            if (gregorianCalendarDO.getGmtModified() != null) {
                gregorianCalendarQuery.setGmtModifiedStart(DateKit.getBeforeDay(gregorianCalendarDO.getGmtModified(),-1));
                gregorianCalendarQuery.setGmtModifiedEnd(DateKit.getBeforeDay(gregorianCalendarDO.getGmtModified(),1));
            }
        }
        return gregorianCalendarQuery;
    }

    /**
     * 保存示例
     * @return GregorianCalendarVO
     */
    public GregorianCalendarVO saveGregorianCalendarExample(){
        GregorianCalendarAddDTO addDTO = this.getGregorianCalendarAddDTO();
        GregorianCalendarVO gregorianCalendarVO = gregorianCalendarService.save(addDTO,buildTokenUser());
        return gregorianCalendarVO;
    }


}

